package com.project.class8_23.work;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test {
    public static void main(String[] args) {
        Plate p = new Plate();
        FutureTask<Integer> dz = new FutureTask<Integer>(new Callable<Integer>() {
            private int count;
            @Override
            public Integer call() throws Exception {
                while(p.num != 0){
                    count++;
                    p.num --;
                    Thread.sleep(300);
                }
                return count;
            }
        });
        FutureTask<Integer> xm = new FutureTask<Integer>(new Callable<Integer>() {
            private int count;
            @Override
            public Integer call() throws Exception {
                while(p.num != 0){
                    count++;
                    p.num --;
                    Thread.sleep(500);
                }
                return count;
            }
        });

        new Thread(dz).start();
        new Thread(xm).start();

        try {
            System.out.println("大壮吃了："+dz.get()+"   小明吃了:"+xm.get());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

class Plate{
    /**饺子数量*/
    public volatile int num = 25;
}